﻿using Guoc.BigMall.Web.Services;
using Guoc.BigMall.WebService;
using Guoc.BigMall.WebService.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Guoc.BigMall.Web.Controllers
{
    public class SaleOrderController : Controller
    {

        ISaleOrderService _orderService;
        public SaleOrderController(ISaleOrderService orderService)
        {
            this._orderService = orderService;
        }

        [TokenAuthorize]
        [HttpPost]
        public ActionResult PlaceOrder(SaleOrderCreateDto model)
        {
            var orderId = _orderService.PlaceOrder(model);
            return new JsonNetResult(ResultModel.Ok(orderId));
        }

       // [TokenAuthorize]
        [HttpPost]
        public ActionResult ConfirmPay(PayOrderDto model)
        {
            model.IpAddress = Request.UserHostAddress;
            var payModel = _orderService.ConfirmPay(model);
            return new JsonNetResult(ResultModel.Ok(payModel));
        }


        [HttpGet]
        public ActionResult Detail(int orderId)
        {
            var model = _orderService.GetOrderDetail(orderId);
            return new JsonNetResult(ResultModel.Ok(model));
        }

        /// <summary>
        ///  查询订单商品列表
        /// </summary>
        /// <param name="pids">订单商品数量字符串对.格式：  "pid-qty,pid2-qty2,pid3-qty3" </param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult OrderProduct(string pids)
        {
            var model = _orderService.GetOrderProduct(pids);
            return new JsonNetResult(ResultModel.Ok(model));
        }
    }
}